package com.gxljc.bear.crawler.cli;

import com.gxljc.commons.quartz.QuartzExecutor;
import com.gxljc.commons.util.AdvCli;
import com.gxljc.commons.util.CliRunner;
import com.gxljc.bear.crawler.weixin.*;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.log4j.Logger;


/**
 * 微信爬虫.
 */
public class WeixinRsyncCli implements QuartzExecutor, CliRunner {
    public static final Logger LOG = Logger.getLogger(WeixinRsyncCli.class);

    // 每13分触发
    private static final String CRON_EXP1 = "0 */13 * * * ?";


    @Override
    public Options initOptions() {
        Options options = new Options();
        options.addOption(AdvCli.CLI_PARAM_HELP, false, "WeixinRsyncCli print help message");
        // run periodically
        options.addOption("quartz", false, "run in quartz mode");
        options.addOption("once", false, "run in once mode");
        return options;
    }

    @Override
    public boolean validateOptions(CommandLine cmdLine) {
        return true;
    }

    @Override
    public void start(CommandLine cmdLine) {
        // if there is no type parameter, do not run the program
        execute();
    }

    @Override
    public void execute() {
        LOG.info("Execute Weixin Rsync.");
        try {
            new RsyncPageCrawler().rsync();
        } catch (Exception e) {
            e.printStackTrace();
        }
        LOG.info("Weixin Rsync done.");
    }

    public static void main(String[] args) {
        AdvCli.initRunner(args, "WeixinRsyncCli", new WeixinRsyncCli());
    }
}
